home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / apps / 29 / gem / gemcl15.doc < prev    next >
Text File  |  1985-11-19  |  14KB  |  258 lines

  1.    Permission to reprint or excerpt is granted only if the
  2. following line appears at the top of the article:
  3.    ANTIC PUBLISHING INC.,COPYRIGHT 1986.  REPRINTED BY PERMISSION.
  4.  
  5.                         Coping with GEMDOS
  6.  
  7.      While it's fun playing with windows and object trees,  one of
  8. the  day-to-day realities of working with the ST is its  operating
  9. system, GEMDOS.  A successful application should insulate the user
  10. from  the foibles and occasional calamities of the machine's  file
  11. system.  The GEM environment provides some minimal tools for doing
  12. this,  but a good deal of responsibility still rests with you, the
  13. programmer.
  14.  
  15.       This column (#15 in the ST PRO GEM series) tries to  address
  16. the  GEM/DOS integration problem by providing you some stock  code
  17. for common functions, along with a discussion of some of the worst
  18. "gotchas" lurking for the unwary.  The download for this column is
  19. GMCL15.C, and it can be found in DL3 of PCS-58.  You should obtain
  20. and list this file before proceeding.
  21.  
  22.      A  BIT OF HISTORY.   There has been a good deal of  confusion
  23. in  the Atari press and among developers over what GEMDOS is,  and
  24. how it relates to TOS and CP/M-68K.   It's important to clear this
  25. up,  so  you can get a true picture of what GEMDOS is intended  to
  26. do.  The best way is to tell the story of GEMDOS' origins, which I
  27. can do, because I was there.
  28.  
  29.      As  most developers are aware,  GEM was first implemented  on
  30. the  IBM  PC.   PC GEM performed two functions.   The first was  a
  31. windowed graphics extension to the PC environment.  The second was
  32. a  visual  shell,  the Desktop,  which ran on top of the  existing
  33. operating system, PC-DOS.
  34.  
  35.      When work started on moving GEM to the ST, there were two big
  36. problems.   First,  no STs actually existed.  Second, there was no
  37. operating system on the 68000 with which GEM and the Desktop could
  38. run.   Unix  was  too  large,  and  CP/M-68K lacked  a  number  of
  39. capabilities,  such  as  hierarchical files,  which were needed to
  40. support GEM.
  41.  
  42.      Work on porting the graphics parts of GEM to the 68000 had to
  43. start immediately to meet schedules.   Therefore, CP/M-68K running
  44. on  Apple Lisa's was used to get this part of the project off  the
  45. ground.   Naturally,  the  Alcyon C compiler and other tools which
  46. were native to this environment were used.
  47.  
  48.      In  parallel,  an  effort was begun to write a new  operating
  49. system for the 68000,  which would ultimately become the ST's file
  50. system.   It was designed to be a close clone of PC-DOS,  since it
  51. would   perform   the   same  functions  for  GEM   in   the   new
  52. environment.  At  this  point,  the term TOS was introduced.   TOS
  53. really meant "the operating system,  whatever it may be, that will
  54. run on the ST",  since not even the specifications,  let alone the
  55. code, were complete at that time.
  56.  
  57.      The  first engineer to work on "TOS" at Digital Research  was
  58. Jason  Loveman.   This  name  leaked  to the press,  and  in  some
  59. distorted  fashion generated a rumor about "Jason DOS",  which was
  60. still  just  the same unfinished project.   As "TOS"  became  more
  61. solid,  the  developer's tools were ported to the new  environment
  62. one by one, and the GEM programming moved with them.  CP/M-68K was
  63. completely  abandoned,  though the old manuals for C and the tools
  64. lived on and are still found in the Atari developer's kit.
  65.  
  66.      All of this work had been done on Lisas or Compupro  systems
  67. fitted with 68000 boards.   At this point,  workable ST prototypes
  68. became  available.   An  implementation  of "TOS" for  the  target
  69. machine  was  begun,  even before the basic operating  system  was
  70. fully completed.
  71.  
  72.      The  other  intent for the new operating system was to  be  a
  73. base for GEM on other 68000 systems as well as the ST.  Because of
  74. this,  Digital  Research  named  it  GEMDOS when  it  was  finally
  75. complete,  thus providing the final bit of nomenclature.  "TOS" as
  76. now  found  in the ST is in fact a  particular  implementation  of
  77. generic GEMDOS, including the ST specific BIOS.
  78.  
  79.      So,  GEMDOS is a PC-DOS clone,  but,  not quite.  There are
  80. enough  differences  to  cause  problems  if  they  are   ignored.
  81. (Remember,  it looks like a duck, and quacks like a duck, but it's
  82. not a duck.)
  83.  
  84.      GOING  FOR  IT.   As a first example,  consider the  routines
  85. open_file()  and create_file() at the beginning of  the  download.
  86. They make use of the GEMDOS calls Fopen() and Fcreate().  You will
  87. notice that these names are not the ones specified in the  Digital
  88. Research  GEMDOS  manual.   Developers who have used PC  GEM  will
  89. also  observe that they are radically different from the  function
  90. names in the PC-DOS bindings.
  91.  
  92.      In  fact,  all  of  the GEMDOS function calls on the  ST  are
  93. defined  as  macros  in the file osbind.h,  distributed  with  the
  94. developer's  kit.   At compile time they are turned into calls  to
  95. the  assembly  language  routine gemdos(),  part of  the  osbind.o
  96. binary.  So, if you find the naming conventions to be particularly
  97. offensive  for  some reason,  just edit the appropriate macros  in
  98. osbind.h.
  99.  
  100.      In  DRI's PC-DOS bindings,  any error codes were returned  in
  101. the  global  variable  DOS_ERR.    In  the  GEMDOS  bindings,  the
  102. operation result or an error code is returned as the value of  the
  103. calling  function.   In  the  case of Fopen() and  Fcreate(),  the
  104. result  is  a  valid file handle if it is  positive.   A  negative
  105. result  is  always an error code,  indicating that  the  operation
  106. failed.
  107.  
  108.      An application which encounters a GEMDOS error should display
  109. an  alert,  and  query  for  retry or abort.   The  type  of  loop
  110. structure  exemplified  by open_file()  and  create_file()  should
  111. be  usable with most GEMDOS functions which might fail.   The  AES
  112. provides  a  function,  form_error,  which  implements  a  set  of
  113. "canned" error alerts appropriate to the various possible errors.
  114.  
  115.      However,  this is where the fun starts.  For unknown reasons,
  116. the form_error on the ST expects to see PC-DOS,  not GEMDOS, error
  117. codes as it's input!  Therefore you need a routine to translate one
  118. into the other.   The routine dos_error() in the download provides
  119. this  function.   The  GEMDOS errors are in the same  sequence  as
  120. those  for  PC-DOS,  but  their numerical order  is  reversed  and
  121. shifted.   Notice  also  that  dos_error() does  NOT  perform  the
  122. translation if the error code is less than -50.   These codes have
  123. no  PC-DOS  equivalent;  computing a bogus translation will  cause
  124. form_error to crash.   Instead,  they are passed through verbatim,
  125. resulting in a "generic" alert which gives only the error number.
  126.  
  127.      The  other major task in integrating a GEM  application  with
  128. the  file  system is selecting file names for  input  and  output.
  129. Again,  the AES provides some assistance with the fsel_input call,
  130. which invokes the standard file selector dialog.
  131.  
  132.      There  are several drawbacks to the standard  file  selector.
  133. One  is that the "ITEM SELECTOR" title is constant and  cannot  be
  134. changed  by the application.   This could cause confusion  for
  135. the  user,  since it may not be clear which of several  functions,
  136. closely spaced in the FILE menu,  was actually invoked.   While it
  137. might  be  possible  to find and "rewire" the  AES  resource  that
  138. defines  the file selector,  it is unlikely that such an  approach
  139. would be portable to a later version of ST GEM.
  140.  
  141.      A  viable approach to eliminating confusion is to  display  a
  142. small "marquee" box, with a message defining the operation, on the
  143. screen  just  above  the  file selector.  To  do  this,  you  must
  144. initialize  the location of the box so that it is outside  of  the
  145. file selector's bounds,  and then draw it just before invoking the
  146. file  selector.   This  way  they will  appear  together.   Before
  147. returning  to its main event loop,  the application should post  a
  148. redraw  message for the "marquee" area.   The AES will merge  this
  149. redraw  with the one generated by fsel_input,  and the result will
  150. be received by the application's evnt_multi.
  151.  
  152.      Another problem with the file selector is that it resets your
  153. application's virtual workstation clip rectangle without  warning.
  154. There  are other AES functions,  such as objc_draw,  which also do
  155. this,  but  the file selector can be troublesome because it may be
  156. the only AES call used by some VDI-based ST applications.
  157.  
  158.      The veteran developer will also notice that the file selector
  159. takes  and returns the path and filename as two separate  strings,
  160. while the GEMDOS file functions require a fully pathed file  name.
  161. Also, the file selector doesn't remember its "home" directory; you
  162. are responsible for determining the default directory, and keeping
  163. track of any changes.  The remainder of the download and column is
  164. devoted  to  set of utilities which should alleviate some  of  the
  165. "grunt work" of these chores.
  166.  
  167.      The  top level routine in this collection is get_file().   It
  168. is  called with two string arguments.   The first must point to  a
  169. four  byte string area containing the desired file name  extension
  170. (three  characters plus a null).   The second is the default  file
  171. name.
  172.  
  173.      If the default file name is non-null, then get_file() invokes
  174. parse_fname() to break it into path and name.   Parse_fname() also
  175. adds  the  necessary "wild card" file specification to  the  path,
  176. using the extent name given as input.
  177.  
  178.      If  no  default  file was supplied,  or the default  did  not
  179. contain  a  path,  the routine get_path() is invoked to  find  the
  180. current  default directory and construct a legal path  string  for
  181. it.
  182.  
  183.      The   results   of  these  manipulations  are   supplied   to
  184. fsel_input.   Notice  that  the  result of the  file  selector  is
  185. returned via its third argument,  rather than as a function value.
  186. If  the result is TRUE,  get_file() merges the temporary path  and
  187. file  string,  storing the result via the second input  parameter.
  188. This  result  string is suitable for use with Fopen,  and  may  be
  189. resubmitted  to get_file() when the next operation is  invoked  by
  190. the user.
  191.  
  192.      Parse_fname() is straight-forward C.  It looks backward along
  193. the  file to find the first character which is part of  the  path.
  194. The tail of the filename is copied off, and its former location is
  195. overlaid with the wild card specification.
  196.  
  197.      Get_path()  is a bit more interesting.   It makes use of  two
  198. GEMDOS  functions,  Dgetdrv() and Dgetpath() to obtain the default
  199. disk drive and directory, respectively.  Note that Dgetpath() will
  200. return  a null string if the current default is the root,  but  it
  201. puts  a back-slash at the beginning of the path  otherwise.   This
  202. forces  a  check for insertion in the root case,  since  the  file
  203. selector  wants  to  see something like  "A:\*.RSC",  rather  than
  204. "A:*.RSC".   After  making  this fix,  get_path() concatenates the
  205. wild card specification derived from the input extent.
  206.  
  207.      The last routine in the download is new_ext().   This utility
  208. is  useful if your application uses more than one associated  file
  209. at a time.   For instance, the Resource Construction Set uses both
  210. an RSC and a DEF file, with the same base name.  New_ext() takes a
  211. fully  formed file name,  and replaces its old extent with the new
  212. one  which you supply.   This lets you quickly generate both  file
  213. names after one call to the file selector.   Notice that new_ext()
  214. looks BACKWARD along the name to find the delimiting period, since
  215. this  character  can also be part of a subdirectory  name  in  the
  216. path.
  217.  
  218.      So  we reach the end of the code and this column.   Hopefully
  219. both will keep you profitably occupied for a while.  July's column
  220. will return to graphics topics,  with a look at writing customized
  221. rubber  box and drag box routines,  and ways to implement your own
  222. "pop-up"  menus.   August  will  bring techniques  for  displaying
  223. progress  indicators,  associating  dialog and menu  entries  with
  224. keystrokes, and customizing objc_edit.
  225.  
  226.      I  CAN'T HEAR YOU!   The Feedback mailbag has been  noticably
  227. flat  of  late.   There have been a number of compliments  on  the
  228. column,  which  are  much  appreciated,  and some suggestions  for
  229. topics  which fall outside the bounds of this series.   The latter
  230. have  been passed on to Antic for possible inclusion in their  new
  231. ST quarterly, START.
  232.  
  233.      One recurring problem is finding the downloads.   A number of
  234. the  earlier columns say they are in PCS-132 (the old  SIG*ATARI),
  235. and  one says PCS-57 (mea culpa).   In fact,  ALL of the downloads
  236. are  now  in DL3 of PCS-58 (ATARI16).   Filenames for  first  nine
  237. columns  are  all in the form GEMCLx.C,  where x is  the  column's
  238. digit.   For reasons unknown to me,  the next two files were named
  239. GEMC10.C  and  GEMC11.C;  the  latest  two  downloads  are  called
  240. GMCL13.C and GMCL15.C.   The latter naming pattern should continue
  241. into the future.
  242.  
  243.      Undoubtedly,  one reason for the shortage of questions is the
  244. amazing ability to get a quick answer on the Developer's SIG, PCS-
  245. 57.   This  is  a  good  sign  of  a  strong  Atari  community  on
  246. Compuserve.   However,  the  SIG message style doesn't really lend
  247. itself  to lengthy explanation,  so suggestions for longer  topics
  248. are always welcome here.
  249.  
  250.      Finally,  I  am now beginning the process of collecting these
  251. columns and some additional material into a book.  In doing so, it
  252. would  be  helpful to know if you feel that any part of  GEM  has
  253. been  slighted  in my discussions.   If so,  let  me  know.   Your
  254. suggestions will appear in future columns and finally make their
  255. way into the book.
  256.  
  257.  
  258.